package com.sangeng.ss.service.impl;

import com.sangeng.ss.domain.LoginUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2024/03/06 8:58
 */
@Service("SDAuth")
public class SelfDefineAuthority {

//    private static final List<String> permissions = Arrays.asList("test","aaa","bbb");


    public boolean hasPermission(String needPermission){
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        if (CollectionUtils.isEmpty(permissions)){
            return false;
        }
        return permissions.contains(needPermission);
    }

}
